<template>
  <div class="product-details">
    <c-header :active="type" @changeType="getType"></c-header>
    <div class="title">案例灵感-详情</div>
    <div class="main">
      <div class="product-title">
        <img src="@/assets/img/case-d-icon.png" alt />
        <span class="product-title_name">{{caseDetails.title}}</span>
      </div>
      <div class="case-d-info">
        <p>项目位置：{{caseDetails.areas}}</p>
        <p>项目时间：{{caseDetails.yeartxt}}</p>
        <p>
          产品系列：
          <a
            href="javascript:;"
            v-if="caseDetails.product"
          >{{productType(caseDetails.product[0].producttype)}}</a>
        </p>
      </div>
      <Swiper :carouselArr="caseDetails.images" class="swiper-container-product_details">
        <swiper-slide class="swiper-slide" v-for="(item,index) in caseDetails.images" :key="index">
          <img :src="item" alt />
        </swiper-slide>
      </Swiper>
      <div class="product-content" v-html="caseDetails.content"></div>
      <div class="product-use">案例使用花色</div>
      <div class="case-use-box">
        <div
          class="news-li"
          v-for="(item, index) in caseDetails.product"
          :key="index"
          @click="toProduct"
        >
          <div class="news-li-hd">
            <img :src="item.imgurl" :alt="item.product_name" />
          </div>
          <div class="news-li-bd">
            <p class="news-li-bd_sign">
              <img src="@/assets/img/product_type01.png" alt v-if="item.producttype==0" />
              <img src="@/assets/img/product_type02.png" alt v-if="item.producttype==1" />
            </p>
            <p class="news-li-bd_title">{{item.product_name}}</p>
            <p class="news-li-bd_desc">{{item.code}}</p>
          </div>
        </div>
      </div>
      <div class="product-use">案例推荐</div>
      <div class="case-box">
        <div class="case-li" v-for="(item, index) in caseArr" :key="index">
          <router-link :to="{path:'/case-details', query:{id: item.id, type: type}}">
            <img :src="item.img_url" :alt="item.title" />
            <p class="case-li-title">{{item.title}}</p>
          </router-link>
        </div>
      </div>
    </div>
    <c-footer :type="type" @changeType="getType"></c-footer>
  </div>
</template>

<script>
import Swiper from "@/components/Swiper/Swiper";
import { caseDetail } from "@/api/index";
export default {
  name: 'caseDetails',
  components: {
    Swiper
  },
  data() {
    return {
      type: this.$route.query.type ? this.$route.query.type : 0,
      id: this.$route.query.id ? this.$route.query.id : 0,
      caseDetails: {},
      caseArr: []
    };
  },
  created() {
    this.init(this.id);
  },
  watch: {
    "$route.query.id": function(id) {
      this.init(id);
    }
  },
  computed: {
    productType() {
      return function(type) {
        return type == 0 ? "强化复合地板" : "实木复合地板";
      };
    }
  },
  methods: {
    getType(type) {
      this.type = type;
    },
    init(id) {
      this.$vux.loading.show({
        text: "Loading"
      });
      caseDetail({
        id: id
      }).then(res => {
        const { code, msg, data } = res;
        setTimeout(() => {
          this.$vux.loading.hide();
        }, 500);
        if (code == 200) {
          this.caseDetails = data.row;
          this.caseArr = data.push;
        }
      });
    },
    toProduct() {
      this.$router.push({
        path: "/product",
        query: {
          type: this.type
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.main {
  padding: 0 0.21rem;

  .swiper-container-product_details {
    height: 3.8rem;

    img {
      width: 100%;
    }
  }

  .product-title {
    margin: 0.27rem 0 0.18rem;
    font-size: 0.36rem;
    color: #2f2d2e;
    display: flex;
    align-items: center;

    .product-title_name {
      width: 90%;
      display: block;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    img {
      display: inline-block;
      width: 0.54rem;
      margin-right: 0.18rem;
    }
  }

  .product-content {
    margin-top: 0.27rem;
    margin-bottom: 0.27rem;
    border-bottom: 1px solid #eaeaea;
    padding-bottom: 0.27rem;
  }

  .case-d-info {
    background: #f8f8f8;
    padding: 0.27rem 0 0.27rem 0.45rem;

    a {
      color: #000;
      text-decoration: underline;
    }
  }

  .product-use {
    font-size: 0.36rem;
    line-height: 1;
  }
  .case-use-box {
    padding-top: 0.36rem;

    .news-li {
      display: flex;
      color: #000;
      padding-bottom: 0.36rem;
      border-bottom: 1px #ccc solid;
      margin-bottom: 0.36rem;
      &:last-child {
        border-bottom: none;
        margin-bottom: 0;
      }
      .news-li-hd img {
        display: block;
        width: 2.17rem;
        height: 2.26rem;
      }

      .news-li-bd {
        margin-left: 0.18rem;

        .news-li-bd_sign img {
          width: 60%;
        }

        .news-li-bd_title {
          font-weight: bold;
          font-size: 0.28rem;
        }

        .news-li-bd_desc {
          color: #cd873f;
          font-size: 0.25rem;
        }
      }
    }
  }

  .case-box {
    padding: 0.36rem 0;

    .case-li {
      margin-bottom: 0.36rem;

      img {
        display: block;
        width: 100%;
        height: 4.72rem;
      }

      p {
        font-size: 0.25rem;
        line-height: 0.43rem;
        margin-top: 0.09rem;
        color: #2d2d2d;
      }
    }
  }
}
</style>
